/*
 * @(#)GenerateTestRecord.java
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;

/**
  GenerateTestRecord.java

  This class is for generation of bean object.

  @author      Rollo Chan
  @company     DCIVision Limited
  @creation date   26/06/2003
  @version     $Revision: 1.7 $
*/

public class GenerateTestRecord {

  public static final String REVISION = "$Revision: 1.7 $";

  static String author = null;
  static String srcPath = null;
  static String driverStr = null;
  static String dbConnStr = null;
  static String dbUsername = null;
  static String dbPassword = null;

  static String packageName = "com.dcivision.";

  static final String JAVA_INTEGER = "Integer";
  static final String JAVA_DECIMAL = "Float";
  static final String JAVA_STRING = "String";
  static final String JAVA_DATE = "Timestamp";

  static Connection conn = null;
  static String sqlStat = null;
  static Statement stat = null;
  static ResultSet rs = null;
  static ResultSetMetaData rsmd = null;

  public static void main(String[] argv) throws Exception {
    // Load properties in the "src" directory.
    java.util.Properties props = new java.util.Properties();
    String path = new GenerateTestRecord().getClass().getProtectionDomain().getCodeSource().getLocation().toString().substring(6);
    if (!path.endsWith("/")) {
      path += "/";
    }
    path += "../../../src/generate.properties";
    java.io.FileInputStream fis = new java.io.FileInputStream(new java.io.File(path));
    props.load(fis);

    author = props.getProperty("author");
    srcPath = props.getProperty("srcPath");
    driverStr = props.getProperty("driverStr");
    dbConnStr = props.getProperty("dbConnStr");
    dbUsername = props.getProperty("dbUsername");
    dbPassword = props.getProperty("dbPassword");

    // Initialize database connection.
    openDBConn();

    stat = conn.createStatement();

    for (int i = 500001; i < 550000; i++) {
      String loginName = com.dcivision.framework.Crypt.encrypt("login" + i, "dcivision");
      stat.execute("INSERT INTO USER_RECORD VALUES ("+i+", '"+loginName+"', '"+loginName+"', 'login"+i+"', 'login"+i+"', 'login "+i+" hee', NULL, NULL, NULL, NULL, '2003-07-07 11:52:15', 'A', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'A', 0, 0, '2003-07-07 00:00:00', 0, '2003-07-07 00:00:00')");
    }

    // Initialize database connection.
    closeDBConn();
  }

  public static void openDBConn() throws Exception {
    Class.forName(driverStr);
    conn = DriverManager.getConnection(dbConnStr, dbUsername, dbPassword);
  }

  public static void closeDBConn() throws Exception {
    try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
    try { stat.close(); } catch (Exception ignore) {} finally { stat = null; }
    try { conn.close(); } catch (Exception ignore) {} finally { conn = null; }
  }
}
